from Business.url import url_index
from selenium.webdriver.remote.webdriver import WebDriver
from HTMLReport import logger

from Common.selenium_tools import add_image


def login(driver: WebDriver, username, password):  # driver: WebDriver  注解 driver类型为 WebDriver
    """完成登录功能

    :param driver: 浏览器实例
    :param username: 用户名
    :param password: 密码
    :return: None
    """
    logger().info("进行登录操作")
    driver.get(url_index)
    logger().info(f"打开URL：{driver.current_url}")
    add_image(driver)
    driver.find_element_by_partial_link_text("请登录").click()
    logger().info("点击登录按钮")
    add_image(driver)
    driver.find_element_by_name("username").send_keys(username)
    logger().info(f"输入用户名：{username}")
    add_image(driver)
    driver.find_element_by_name("password").send_keys(password)
    logger().info(f"输入密码：{password}")
    add_image(driver)
    driver.find_element_by_name("submit").click()
    logger().info("点击登录按钮")
